﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using ROrganizer.Client;

namespace ROrganizer.UI.Controllers
{
    internal class FolderManagerFormController
    {
        private readonly ObservableCollection<string> folders;
        private readonly ApplicationSettings settings;

        public FolderManagerFormController()
        {
            this.settings = ApplicationSettings.GetInstance();
            this.folders = new ObservableCollection<string>(this.settings.GetFolders());
        }

        public bool IsChanged { get; private set; }
        public ObservableCollection<string> Folders
        {
            get { return this.folders; }
        }

        public void AddFolder(string path)
        {
            if (!this.folders.Contains(path))
            {
                this.folders.Add(path);
                this.settings.AddFolder(path);
                ApplicationSettings.Persist(settings);
                this.IsChanged = true;
            }
        }

        public void RemoveFolders(string[] paths)
        {
            foreach (var path in paths)
            {
                this.folders.Remove(path);
                this.settings.RemoveFolder(path);
            }

            ApplicationSettings.Persist(settings);
            this.IsChanged = true;
        }
    }
}
